package cn.zhaoguang.usedcar.main.controller;

import cn.zhaoguang.usedcar.common.http.ResultVO;
import cn.zhaoguang.usedcar.common.page.PageRequest;
import cn.zhaoguang.usedcar.main.entity.vo.SellerAddVO;
import cn.zhaoguang.usedcar.main.entity.vo.SellerUpdateInfoVO;
import cn.zhaoguang.usedcar.main.entity.vo.SellerUpdatePasswordVO;
import cn.zhaoguang.usedcar.main.service.SellerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description
 * @Author zhaoguang
 * @Date 2021/7/3 11:22
 */
@RestController
@RequestMapping("/seller")
@Api(tags = "商家控制器")
public class SellerController {

    @Autowired
    private SellerService sellerService;

    @PostMapping("/add")
    @ApiOperation(value = "添加", notes = "添加商家")
    public ResultVO add(@RequestBody SellerAddVO seller) {
        String result = sellerService.add(seller);
        return ResultVO.success(result);
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除", notes = "根据id删除商家")
    public ResultVO delete(@PathVariable("id") Integer id) {
        int result = sellerService.delete(id);
        if (result > 0) {
            return ResultVO.success("删除成功");
        }
        return ResultVO.error("删除失败");
    }

    @PutMapping("/updateInfo")
    @ApiOperation(value = "修改商家信息", notes = "修改商家信息")
    public ResultVO update(@RequestBody SellerUpdateInfoVO sellerInfo) {
        String result = sellerService.updateInfo(sellerInfo);
        return ResultVO.success(result);
    }

    @PutMapping("/updatePassword")
    @ApiOperation(value = "修改商家密码", notes = "修改商家密码")
    public ResultVO updatePassword(@RequestBody SellerUpdatePasswordVO sellerPassword) {
        String result = sellerService.updatePassword(sellerPassword);
        return ResultVO.success(result);
    }

    @GetMapping("/listAllSellerOnMap")
    @ApiOperation(value = "用户接口-在地图上查询全部商家", notes = "在地图上查询全部商家")
    public ResultVO listAllSellerOnMap() {
        return ResultVO.success("查询成功", sellerService.listAllSellerOnMap());
    }

    @PostMapping("/listAllSellerForManager")
    @ApiOperation(value = "管理员接口-获取所有商家信息", notes = "获取所有商家信息")
    public ResultVO listAllSellerForManager(@RequestBody PageRequest pageRequest) {
        return ResultVO.success("查询成功",sellerService.listAllSellerForManager(pageRequest));
    }
}
